package com.blog.study.study2;

import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;

/**
 * 软引用.
 *
 * @author 张俊强~.
 * @date 2017/11/17-21:41.
 */
public class SoftReferenceDemo {

    public static void main(String[] args) {
        Map m = new HashMap();
        Object obj = new Object();
        SoftReference<Object> sf = new SoftReference<Object>(obj);
        int i = 0;
        for (int j = 0; i < 80000; j++) {
            m.put(i, new String("没有释放空间"));
            if (sf.get() == null) {
                System.out.println("空间已经释放");
            }
            i++;
        }

    }
}
